﻿package	birdry.ui {
	import flash.events.Event;
	import flash.utils.ByteArray;
	import flash.display.MovieClip;
	import flash.media.*;
	import gs.TweenMax;
	
	public class Spectrum extends MovieClip	{
		var float:Number;
		var Easing:String;
		var mArray:Object;
		var bArray:ByteArray;
		var Time:Number;
		public function Spectrum(mArray:Object, bArray:ByteArray, Time:Number = 0.2):void	{
			// var Time:Number = 0.2;
			this.mArray = mArray;
			this.bArray = bArray;
			this.Time = Time;
			for(var i=0; i<mArray.length; ++i)	{
				mArray[i].scaleY = 0;
			}
			mArray[0].addEventListener(Event.ENTER_FRAME, onPlay);
		}
		
		override public function play(): void	{
			mArray[0].addEventListener(Event.ENTER_FRAME, onPlay);
		}
		override public function stop(): void	{
			mArray[0].removeEventListener(Event.ENTER_FRAME, onPlay);
		}

		
		public function Init():void	{
			for(var i=0; i<mArray.length; ++i)	{
				Easing = "linear"
				TweenMax.to(mArray[i], Time, { scaleY:0 } );
			}
		}
		
		private function onPlay(e:Event):void		{
			SoundMixer.computeSpectrum(bArray,true,0);
			for(var i=0; i<mArray.length; ++i)	{
				float = bArray.readFloat();
				if(float > 1) float = 1;
				if(mArray[i].scaleY < float)	{
					TweenMax.to(mArray[i], Time, { scaleY:float } );
				}	else	{
					TweenMax.to(mArray[i], Time*5, { scaleY:float } );
				}
				
			}
		}
	}	// class
}	//	package